/**
 * 判断点是否在一个三角形内
 */

function vec(a, b) {
  return {
    x: b.x - a.x,
    y: b.y - a.y
  }
}

function vecProduct(v1, v2) {
  return v1.x * v2.y - v2.x * v1.y;
}

function sameSymbols(a, b) {
  return (a ^ b) >= 0;
}

function pointInTriangle(p, a, b, c) {
  var PA = vec(p, a),
    PB = vec(p, b),
    PC = vec(p, c),
    R1 = vecProduct(PA, PB),
    R2 = vecProduct(PB, PC),
    R3 = vecProduct(PC, PA);

  return sameSymbols(R1, R2) && sameSymbols(R2, R3);
}

// -----------------------------------------------

const ChineseNumbers = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']

/**
 * 数学单位
 * * 个 十 百 千 万 亿 兆
 * * 京 10^16
 * * 垓 10^20
 * * 秭 10^24
 * * 穰 沟 涧 正 载 极
 */
const NumberUnit = [
  '', '十', '百', '千',
  '万', '十', '百', '千',
  '亿', '十', '百', '千',
  '兆', '十', '百', '千'
]
/**
 * @数字转换
 * @param { Number } num
 */
 const convertToChinaNum = (num) => {
  if (!num || isNaN(num)) {
    return '零'
  }
  var english = num.toString().split('')
  var result = ''
  for (var i = 0; i < english.length; i++) {
    var des_i = english.length - 1 - i
    result = NumberUnit[i] + result
    var ChineseNumbers_index = english[des_i]
    result = ChineseNumbers[ChineseNumbers_index] + result
  }
  result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十')
  result = result.replace(/零+/g, '零')
  result = result.replace(/零亿/g, '亿').replace(/零万/g, '万')
  result = result.replace(/亿万/g, '亿')
  result = result.replace(/零+$/, '')
  result = result.replace(/^一十/g, '十')
  return result
}

// ----------------------------------------------------------